home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Tool Chest / Text / WASTE / WASTE 1.1.2 Distribution / Demo Source / WEDemoIntf.p < prev    next >
Encoding:
Text File  |  1995-10-12  |  5.2 KB  |  258 lines  |  [TEXT/CWIE]

  1. unit WEDemoIntf;
  2.  
  3. { WASTE DEMO PROJECT: }
  4. { Global interface: constant, type and class declarations used in most other units }
  5.  
  6. { Copyright © 1993-1995 Marco Piovanelli }
  7. { All Rights Reserved }
  8.  
  9. interface
  10.     uses
  11.         Types, Resources, Quickdraw, Menus, Windows, Controls, WASTE;
  12.  
  13.     const
  14.  
  15. { WASTE demo signature }
  16.  
  17.         kAppSignature = 'OEDE';
  18.  
  19. { resource types, clipboard types and file types }
  20.  
  21.         kTypeDeskAccessory = 'DRVR';
  22.         kTypeFont = 'FONT';
  23.         kTypePicture = 'PICT';
  24.         kTypeSound = 'snd ';
  25.         kTypeSoup = 'SOUP';
  26.         kTypeStyles = 'styl';
  27.         kTypeText = 'TEXT';
  28.  
  29. { menu IDs }
  30.  
  31.         kMenuApple = 1;
  32.         kMenuFile = 2;
  33.         kMenuEdit = 3;
  34.         kMenuFont = 4;
  35.         kMenuSize = 5;
  36.         kMenuStyle = 6;
  37.         kMenuColor = 7;
  38.         kMenuFeatures = 8;
  39.         kMenuAlignment = 9;
  40.  
  41. { Apple menu items }
  42.  
  43.         kItemAbout = 1;
  44.  
  45. { File menu items }
  46.  
  47.         kItemNew = 1;
  48.         kItemOpen = 2;
  49.         kItemClose = 4;
  50.         kItemSave = 5;
  51.         kItemSaveAs = 6;
  52.         kItemQuit = 8;
  53.  
  54. { Edit menu items }
  55.  
  56.         kItemUndo = 1;
  57.         kItemCut = 3;
  58.         kItemCopy = 4;
  59.         kItemPaste = 5;
  60.         kItemClear = 6;
  61.         kItemSelectAll = 7;
  62.  
  63. { Size menu items }
  64.  
  65.         kItemLastSize = 6;
  66.         kItemSmaller = 8;
  67.         kItemLarger = 9;
  68.  
  69. { Style menu items }
  70.  
  71.         kItemPlainText = 1;
  72.         kItemBold = 2;
  73.         kItemItalic = 3;
  74.         kItemUnderline = 4;
  75.         kItemOutline = 5;
  76.         kItemShadow = 6;
  77.         kItemCondensed = 7;
  78.         kItemExtended = 8;
  79.  
  80. { Color menu items }
  81.  
  82.         kItemBlack = 1;
  83.         kItemRed = 2;
  84.         kItemGreen = 3;
  85.         kItemBlue = 4;
  86.         kItemCyan = 5;
  87.         kItemMagenta = 6;
  88.         kItemYellow = 7;
  89.  
  90. { Alignment menu items }
  91.  
  92.         kItemAlignDefault = 1;
  93.         kItemAlignLeft = 3;
  94.         kItemCenter = 4;
  95.         kItemAlignRight = 5;
  96.         kItemJustify = 6;
  97.  
  98. { Features menu item }
  99.  
  100.         kItemAlignment = 1;
  101.         kItemTabHooks = 2;
  102.         kItemAutoScroll = 4;
  103.         kItemOutlineHilite = 5;
  104.         kItemReadOnly = 6;
  105.         kItemIntCutAndPaste = 7;
  106.         kItemDragAndDrop = 8;
  107.         kItemOffscreenDrawing = 9;
  108.  
  109. { Alert & dialog template resource IDs }
  110.  
  111.         kAlertNeedSys7 = 128;
  112.         kAlertGenError = 130;
  113.         kAlertSaveChanges = 131;
  114.         kDialogAboutBox = 256;
  115.  
  116. { String list resource IDs }
  117.  
  118.         kUndoStringsID = 128;
  119.         kClosingQuittingStringsID = 129;
  120.  
  121. { miscellaneous resource IDs }
  122.  
  123.         kMenuBarID = 128;
  124.         kWindowTemplateID = 128;
  125.         kScrollBarTemplateID = 128;
  126.         kPromptStringID = 128;
  127.  
  128. { virtual key codes for navigation keys found on extended keyboards }
  129.  
  130.         keyPgUp = $74;
  131.         keyPgDn = $79;
  132.         keyHome = $73;
  133.         keyEnd = $77;
  134.  
  135. { other commonly used constants }
  136.  
  137.         kBarWidth = 16;                { width of a scroll bar }
  138.         kTitleHeight = 20;                { usual height of a window title bar }
  139.         kTextMargin = 3;                { indent of text rect from window port rect }
  140.         kScrollDelta = 11;                { pixels to scroll when the scroll bar arrow is clicked }
  141.  
  142.     type
  143.  
  144. { enumeration types used for closing a window and/or quitting the application }
  145.  
  146.         ClosingOption = (closingWindow, closingApplication);
  147.         SavingOption = (savingYes, savingNo, savingAsk);
  148.  
  149. { a ScrollBarPair is just a pair of control handles }
  150.  
  151.         ScrollBarPair = record
  152.                 case Integer of
  153.                     0: (
  154.                             v, h: ControlRef;
  155.                     );
  156.                     1: (
  157. {$IFC NOT UNDEFINED THINK_PASCAL}
  158.                             vh: array[VHSelect] of ControlRef;
  159. {$ELSEC}
  160.                             vh: array[0..1] of ControlRef;
  161. {$ENDC}
  162.                     );
  163.             end;  { ScrollBarPair }
  164.  
  165. { a DocumentRecord is a window record with additional fields }
  166.  
  167.         DocumentRecord = record
  168.                 window: WindowRecord;                    { the window }
  169.                 scrollBars: ScrollBarPair;                    { its scroll bars }
  170.                 we: WEReference;                                { its WASTE instance }
  171.                 fileAlias: Handle;                                { alias to associated file }
  172.             end;  { DocumentRec }
  173.         DocumentPeek = ^DocumentRecord;
  174.  
  175.     var
  176.  
  177. { global variables }
  178.  
  179.         gHasColorQD: Boolean;            { TRUE if Color QuickDraw is available }
  180.         gHasDragAndDrop: Boolean;    { TRUE if the Drag Manager is available }
  181.         gHasTextServices: Boolean;    { TRUE if the Text Services Manager is available }
  182.         gExiting: Boolean;                    { set this variable to drop out of event loop and quit }
  183.  
  184. { general purpose utility routines }
  185.  
  186.     procedure ErrorAlert (err: OSErr);
  187.     procedure ForgetHandle (var h: univ Handle);
  188.     procedure ForgetResource (var h: univ Handle);
  189.     function NewHandleTemp (blockSize: Size;
  190.                                     var h: univ Handle): OSErr;
  191.  
  192. implementation
  193.     uses
  194.         DialogUtils;
  195.  
  196.     procedure ErrorAlert (err: OSErr);
  197.         var
  198.             errString: Str255;
  199.             alertResult: Integer;
  200.     begin
  201.         NumToString(err, errString);
  202.         ParamText(errString, '', '', '');
  203. {$IFC NOT UNDEFINED THINK_PASCAL}
  204.         SetCursor(arrow);
  205. {$ELSEC}
  206.         SetCursor(qd.arrow);
  207. {$ENDC}
  208.         alertResult := Alert(kAlertGenError, GetMyStandardDialogFilter);
  209.     end;  { ErrorAlert }
  210.  
  211.     procedure ForgetHandle (var h: univ Handle);
  212.         var
  213.             theHandle: Handle;
  214.     begin
  215.         theHandle := h;
  216.         if (theHandle <> nil) then
  217.             begin
  218.                 h := nil;
  219.                 DisposeHandle(theHandle);
  220.             end;
  221.     end;  { ForgetHandle }
  222.  
  223.     procedure ForgetResource (var h: univ Handle);
  224.         var
  225.             theHandle: Handle;
  226.     begin
  227.         theHandle := h;
  228.         if (theHandle <> nil) then
  229.             begin
  230.                 h := nil;
  231.                 ReleaseResource(theHandle);
  232.             end;
  233.     end;  { ForgetResource }
  234.  
  235.     function NewHandleTemp (blockSize: Size;
  236.                                     var h: univ Handle): OSErr;
  237.  
  238. { allocate a new relocatable block from temporary memory or, }
  239. { if that fails, from the current heap }
  240.  
  241.         var
  242.             err: OSErr;
  243.     begin
  244.  
  245. { first try tapping temporary memory }
  246.         h := TempNewHandle(blockSize, err);
  247.         NewHandleTemp := err;
  248.  
  249. { in case of failure, try with current heap }
  250.         if (h = nil) then
  251.             begin
  252.                 h := NewHandle(blockSize);
  253.                 NewHandleTemp := MemError;
  254.             end;
  255.  
  256.     end;  { NewHandleTemp }
  257.  
  258. end.